package com.wavehi.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * @Author WaveHi
 * @Date 17/9/2021 上午 11:37
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description tool class of mybatis
 */
public class MyBatisUtils {
    private static SqlSessionFactory ssf;//连接器工厂
    private MyBatisUtils() {}
    static {
        //获取配置文件输入流
        InputStream in = MyBatisUtils.class.getClassLoader().getResourceAsStream("mybatis-config.xml");
        //获取连接器工厂
        System.out.println(in);
        ssf = new SqlSessionFactoryBuilder().build(in);
    }

    /**
     * 获取数据库连接
     * @return 返回一个数据库会话对象
     */
    public static SqlSession getConnection() {
        return ssf.openSession();
    }


}
